﻿using Acme.SmartWMS.Inbound.OtherInbounds;
using Acme.SmartWMS.Inbound;
using Microsoft.AspNetCore.Mvc;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System;
using Acme.SmartWMS.BasicInfo.CommodityDetails;

namespace Acme.SmartWMS.Web.Controllers.Inbound.OtherInbounds
{
    public class OtherInboundController : Controller
    {

        private readonly IOtherInboundAppService _otherInboundAppService;

        public OtherInboundController(IOtherInboundAppService otherInboundAppService)
        {
            _otherInboundAppService = otherInboundAppService;
        }

        public IActionResult OtherInboundList()
        {
            return View();
        }

        public IActionResult Add()
        {
            return View();
        }

        public IActionResult Edit(int id)
        {
            return View();
        }

        [HttpPost]
        public async Task<int> AddOtherInbound(OtherInboundDTO dto)
        {
            var result = await _otherInboundAppService.AddOtherInbound(dto);
            return result;
        }
        [HttpPost]
        public async Task<int> UpdateOtherInbound(OtherInboundDTO dto)
        {
            var result = await _otherInboundAppService.UpdateOtherInbound(dto);
            return result;
        }
        [HttpPost]
        public async Task<int> DeleteOtherInbound(int id)
        {
            var result = await _otherInboundAppService.DeleteOtherInbound(id);
            return result;
        }
        [HttpGet]
        public JsonResult GetOtherInbound(string? name, int page = 1, int limit = 2)
        {
            var result = _otherInboundAppService.GetOtherInbound(name, page, limit);
            return Json(new { data = result.Queryable, count = result.RowCount, code = "0", msg = "" });
        }
        [HttpGet]
        public JsonResult GetOtherInboundById(int id)
        {
            var result = _otherInboundAppService.GetOtherInboundById(id);
            return Json(new { data = result, code = "0", msg = "" });
        }

        [HttpPost]
        public async Task<int> DeleAll(string id)
        {
            int res = 0;
            foreach (var ids in id.Split(","))
            {
                res = await _otherInboundAppService.DeleteOtherInbound(int.Parse(ids));
            }
            return res; 
        }
    }
}
